package org.heydr.common;

import java.util.Comparator;
import java.util.DuplicateFormatFlagsException;

import org.heydr.annotation.HandleInfo;
import org.heydr.handler.impl.SubHandler;

public class HandlerChainComparator implements Comparator<SubHandler>{

	@Override
	public int compare(SubHandler o1, SubHandler o2) {
		int step1 = o1.getClass().getAnnotation(HandleInfo.class).step();
		int step2 = o2.getClass().getAnnotation(HandleInfo.class).step();
		if(step1==step2){
			String name1 = o1.getClass().getName();
			String name2 = o2.getClass().getName();
			String group = o1.getClass().getAnnotation(HandleInfo.class).group();
			throw new DuplicateFormatFlagsException("both "+ name1 + " and "+name2 +" have the same step in group "+group);
		}
		return step1>step2?1:0;
	}
	
}
